<template>
  <div>
    <el-form label-width="80px" :inline="true" style="margin-top: 20px">
      <el-form-item label="用户账号">
        <el-autocomplete
          v-model="user.account"
          :fetch-suggestions="queryAccount"
          placeholder="用户账号">
        </el-autocomplete>
      </el-form-item>

      <el-form-item label="用户姓名">
        <el-autocomplete
          v-model="user.name"
          :fetch-suggestions="queryName"
          placeholder="用户姓名">
        </el-autocomplete>
      </el-form-item>

      <el-form-item label="电话号码">
        <el-autocomplete
          v-model="user.mobile1"
          :fetch-suggestions="queryMobile"
          placeholder="电话号码">
        </el-autocomplete>
      </el-form-item>

      <el-form-item label="机构/部门">
        <el-cascader
          v-model="orgDepModel"
          placeholder="试试搜索：指南"
          :options="cascadeOptions"
          filterable
          style="width: 250px"
        ></el-cascader>
      </el-form-item>


    </el-form>
  </div>

</template>

<script>
  import {GetOrgDep, GetUserLikeAccount,GetUserLikeName} from '@/api/sysuser'

  export default {
    components: {},
    mounted() {
      GetOrgDep().then(res => {
        console.log('res.data', res.data)
        this.cascadeOptions = res.data
      })
    },
    computed: {},
    data() {
      return {
        user: {
          account: "",
          name: "",
          mobile1: "",
          orgId: '',
          depId: ""
        },
        orgDepModel: [],
        cascadeOptions: []
      }
    },
    methods: {
      queryAccount(queryString, callBack) {
        let selectData = []

        GetUserLikeAccount(queryString).then(res => {
          res.data.forEach(account => {
            selectData.push({'value':account})
          })
        }).then(() => {
          callBack(selectData)
        }).catch(err => {
          this.$message({
            message: err,
            type: 'error'
          })
        })
      },
      queryName(queryString, callBack) {
        let selectData = []
        GetUserLikeName(queryString).then(res=>{
          res.data.forEach(name => {
            selectData.push({'value':name})
          })
        }).then(() => {
          callBack(selectData)
        }).catch(err => {
          this.$message({
            message: err,
            type: 'error'
          })
        })

      },
      queryMobile(queryString, callBack) {

      }
    },
    watch: {
      orgDepModel: function (newArr, oldArr) {
        if (newArr.length >= 2) {
          this.user.orgId = newArr[newArr.length - 2]
          this.user.depId = newArr[newArr.length - 1]
        }

      }
    }
  }
</script>

<style scoped>

</style>
